<template>
    <IDrawer v-model="defaultValue" :loading="loading">
        <Form ref="formCreate" :model="data" label-position="top" :rules="ruleValidate">
            <Row :gutter="10">
                <Col :span="12">
                    <FormItem label="客户名称" prop="name">
                        <Input v-model="data.name"></Input>
                    </FormItem>
                </Col>
                <Col :span="12">
                    <FormItem label="客户状态" prop="status">
                        <RemoteSelect v-model="data.status" url="common/select/dictionaries/CUSTOMER_STATUS"></RemoteSelect>
                    </FormItem>
                </Col>
            </Row>

            <FormItem label="客户备注" prop="remark">
                <Input v-model="data.remark" show-word-limit type="textarea" maxlength="1000"></Input>
            </FormItem>
        </Form>
        <div slot="footer">

            <ButtonGroup>
                <Button type="primary" icon="ios-add" @click="submit('formCreate')">提交</Button>
                <Button type="warning" icon="md-log-out" @click="defaultValue = false">返回</Button>
            </ButtonGroup>
        </div>
    </IDrawer>
</template>

<script>
    import IDrawerMixins from "../../../../mixins/iDrawerMixins";
    import IDrawer from "../../../../components/layout/IDrawer";
    import IData from "./data"
    import RemoteSelect
        from "../../../../../../../vendor/luffyzhao/laravel-admin-auth/src/Pulishes/resources/vue/src/components/form/remoteSelect";

    export default {
        name: "create",
        components: {RemoteSelect, IDrawer},
        mixins: [IDrawerMixins, IData],
        data() {
            return {
                loading: false,
                data: {}
            }
        },
        mounted() {
            this.getData();
        },
        methods: {
            getData(){
                this.loading = true;
                this.$http.get(`customer/index/${this.props.id}`).then((res) => {
                    this.data = res;
                }).finally(() => {
                    this.loading = false;
                });
            },
            submit(name){
                this.validate(name).then(() => {
                    this.loading = true;
                    this.$http.put(`customer/index/${this.props.id}`, this.data).then(() => {
                        this.loading = false;
                    }).finally(() => {
                        this.defaultValue = false;
                    })
                });
            }
        }
    }
</script>

<style scoped>

</style>
